package com.example.apiinterface.controller;

/**
 * @author 25169
 */




import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.crack.simpleapiclientsdk.model.User;
import com.example.apiinterface.mapper.RandomWordsMapper;
import com.example.apiinterface.service.RandomWordsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * 名称API
 * @author 25169
 */
@RestController
@RequestMapping("name")
@Slf4j
public class NameController {

    @Autowired
    private RandomWordsService randomWordsService;

    @GetMapping("/get")
    public String getName(String name) {
        return "GET的name为" + name;
    }

    @PostMapping("/user")
    public String getUserNameByPost(@RequestBody User user){
        return "POST的name为" + user.getUsername();
    }

    @GetMapping("getRandomWords")
    public String getRandomWords(String encode){

        String s = randomWordsService.randomWords();
        String result=null;
        if("json".equals(encode)){
            Map<String,String> map=new HashMap<>();
            map.put("text",s);
            result = JSONUtil.toJsonStr(map);
        }else if ("text".equals(encode)){
            result = s;
        }
        return result;
    }

    @GetMapping("/dyGirl")
    public String getDyGirlGet(String aa1){
        /*Map<String,String> map= new HashMap<>();
        map.put("user-agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36 Edg/111.0.1661.44");
        HttpResponse httpResponse = HttpRequest.get("https://zj.v.api.aa1.cn/api/video_dyv2")
                .addHeaders(map)
                .execute();
        String location = httpResponse.header("Location");
        HttpResponse httpResponse1 = HttpRequest.get(location).execute();
        return httpResponse1.body();*/
        /*//可以单独传入http参数，这样参数会自动做URL编码，拼接在URL中
        HashMap<String, Object> paramMap = new HashMap<>();
        paramMap.put("aa1", aa1);
        String result3= HttpUtil.get("https://zj.v.api.aa1.cn/api/video_dyv2", paramMap);
        return  result3;*/
        return "mamama";
    }



}
